package vim.meet.jdk;

import org.curitis.service.BusinessService;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class DoSomethingInvocationHandler implements InvocationHandler{

    private Object target;

    public DoSomethingInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        for(Object arg : args){
            System.out.println(arg);
        }
        if(proxy instanceof BusinessService){
            if(method.getName().equals("doSomething")){
                String result = (String) method.invoke(target, args);
                return "Hello" + result;
            }
        }
        return method.invoke(target,args);
    }
}
